﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IFRS.Models;

namespace IFRS.DataAccess.DAL
{
    public class SPR_FEEANDCOSTMAPPING
    {
        public DataTable SEARCH_ALL(FeeAndCostMapping feeAndCostMapping, Paging paging, bool isAllBranch, string sCostCenter, ref int iRecordCount)
        {
            DataTable dt;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@RecordCount", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;
                lstParams.Add(new SqlParameter("@PageIndex", paging.PageIndex.AsDBValue()));
                lstParams.Add(new SqlParameter("@PageSize", paging.PageSize.AsDBValue()));
                lstParams.Add(new SqlParameter("@Sorting", paging.Sorting.AsDBValue()));

                lstParams.Add(new SqlParameter("@isAllBranch", isAllBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@sCostCenter", sCostCenter.AsDBValue()));

                lstParams.Add(new SqlParameter("@DataType", feeAndCostMapping.DataType.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", feeAndCostMapping.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeName", feeAndCostMapping.FeeAndCostTypeName.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeNM", feeAndCostMapping.FeeAndCostTypeNM.AsDBValue()));

                dt = utility.StoredProcDataTable("SPR_FEEANDCOSTMAPPING_SEARCHALL", lstParams.ToArray());

                iRecordCount = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public DataTable SEARCH_BYID(int feeAndCostMappingId)
        {
            DataTable dt;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostMappingID", feeAndCostMappingId));
                dt = utility.StoredProcDataTable("SPR_FEEANDCOSTMAPPING_SEARCHBYID", lstParams.ToArray());

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return dt;
        }

        public int INSERT(FeeAndCostMapping feeAndCostMapping)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostMappingID", SqlDbType.Int));
                lstParams[0].Direction = ParameterDirection.Output;

                lstParams.Add(new SqlParameter("@DataType", feeAndCostMapping.DataType.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", feeAndCostMapping.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", feeAndCostMapping.FeeAndCostTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@OrgFeeAndCostTypeID", feeAndCostMapping.OrgFeeAndCostTypeID.AsDBValue()));

                lstParams.Add(new SqlParameter("@CreatedDate", feeAndCostMapping.CreatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBy", feeAndCostMapping.CreatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedCostCenter", feeAndCostMapping.CreatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@CreatedBranch", feeAndCostMapping.CreatedBranch.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", feeAndCostMapping.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", feeAndCostMapping.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", feeAndCostMapping.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", feeAndCostMapping.UpdatedBranch.AsDBValue()));

                utility.ExecuteStoredProc("SPR_FEEANDCOSTMAPPING_INSERT", lstParams.ToArray());

                iNum = (int)lstParams[0].Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int UPDATE(FeeAndCostMapping feeAndCostMapping)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostMappingID", feeAndCostMapping.FeeAndCostMappingID.AsDBValue()));
                lstParams.Add(new SqlParameter("@DataType", feeAndCostMapping.DataType.AsDBValue()));
                lstParams.Add(new SqlParameter("@SourceDataID", feeAndCostMapping.SourceDataID.AsDBValue()));
                lstParams.Add(new SqlParameter("@FeeAndCostTypeID", feeAndCostMapping.FeeAndCostTypeID.AsDBValue()));
                lstParams.Add(new SqlParameter("@OrgFeeAndCostTypeID", feeAndCostMapping.OrgFeeAndCostTypeID.AsDBValue()));

                lstParams.Add(new SqlParameter("@UpdatedDate", feeAndCostMapping.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", feeAndCostMapping.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", feeAndCostMapping.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", feeAndCostMapping.UpdatedBranch.AsDBValue()));

                iNum = (int)utility.ExecuteStoredProc("SPR_FEEANDCOSTMAPPING_UPDATE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }

        public int DELETE(FeeAndCostMapping feeAndCostMapping)
        {
            int iNum;
            var utility = new IFRS_Utility();
            var lstParams = new List<SqlParameter>();
            try
            {
                lstParams.Add(new SqlParameter("@FeeAndCostMappingID", feeAndCostMapping.FeeAndCostMappingID.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedDate", feeAndCostMapping.UpdatedDate.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBy", feeAndCostMapping.UpdatedBy.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedCostCenter", feeAndCostMapping.UpdatedCostCenter.AsDBValue()));
                lstParams.Add(new SqlParameter("@UpdatedBranch", feeAndCostMapping.UpdatedBranch.AsDBValue()));

                iNum = (int)utility.ExecuteStoredProc("SPR_FEEANDCOSTMAPPING_DELETE", lstParams.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return iNum;
        }
    }
}
